<template>
	<!-- 查看报告时判断是不是厂区会员  如果是有权限可以查看没有权限不能查看
	 如果是普通会员   查看需要缴费   跳转页面写入查看报告的好处-->
	<view class="mine-container">
		<scroll-view class="scrollWrap" :enhanced="true" scroll-y :bounces="false" :show-scrollbar="false">
			<view class="header-section">
				<image class="bg" :src="$buildFullImageUrl('/static/consult/mineBg.png')"></image>
				<view class="bg-wrap">
					<view class="head-img" @click="goInfo">
						<view>
							<image :src="form.avatar ? form.avatar : $fullImageUrl('/profile/upload/2025/06/20/1_20250620135318A001.jpg')"></image>
							<view>
								<image :src="$buildFullImageUrl('/static/mine/pencil.svg')"></image>
								<!-- <image v-if="form.userType == 2" :src="$buildFullImageUrl('/static/images/company.png')" style="width: 40rpx; height: 41rpx"></image> -->
							</view>
						</view>
						<view v-if="form.nickName">{{ form.nickName }}</view>
						<view v-if="!form.nickName"></view>
					</view>
					<view class="operate-list">
						<view @click="handleAppointOrder">
							<image :src="$buildFullImageUrl('/static/consult/reservationOrder.png')"></image>
							<text>预约订单</text>
						</view>
						<view @click="handelMyEvaluate">
							<image :src="$buildFullImageUrl('/static/consult/myEvaluation.png')"></image>
							<text>我的测评</text>
						</view>
						<view class="contact">
							<button open-type="contact" @contact="handleContact">
								<image :src="$buildFullImageUrl('/static/consult/customerServiceCenter.png')"></image>
								<text>客服中心</text>
							</button>
							<!-- <image :src="$buildFullImageUrl('/static/consult/customerServiceCenter.png')"></image>
							<text>客服中心</text> -->
						</view>
						<view @click="handelMyAtten">
							<image :src="$buildFullImageUrl('/static/consult/myAttention.png')"></image>
							<text>我的关注</text>
						</view>
					</view>
				</view>
			</view>
			<view class="content-section">
				<view class="content-section-list">
					<!-- 	<view>
						<image :src="$buildFullImageUrl('/static/mine/notic.svg')"></image>
						<text>消息通知</text>
					</view> -->
					<!-- 	<view class="" @click="goPay">支付</view>
					<view class="" @click="backPay">退款</view> -->
					<view @click="goSugget">
						<image :src="$buildFullImageUrl('/static/mine/oponion.svg')"></image>
						<text>意见反馈</text>
					</view>
					<view @click="goSetting">
						<image :src="$buildFullImageUrl('/static/mine/setting.svg')"></image>
						<text>设置</text>
					</view>
					<view @click="goPhone" style="display: flex; align-items: center">
						<view class="">
							<u-icon name="phone" size="18"></u-icon>
						</view>
						<view class="" style="margin-left: 10rpx; color: #666; font-size: 26rpx">心理热线：</view>
						<view class="" style="color: #666; font-size: 26rpx">{{ data }}</view>
						<!-- <image :src="$buildFullImageUrl('/static/mine/setting.svg')"></image> -->
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
import { getInfos } from '@/api/system/user';
import { createOrder, createRefund } from '@/api/weiPay/index';
import { getconfiguration } from '@/api/config/index.js';
export default {
	data() {
		return {
			data: '',
			name: this.$store.state.user.name,
			form: {}
		};
	},
	computed: {
		avatar() {
			return this.$store.state.user.avatar;
		},
		windowHeight() {
			return uni.getSystemInfoSync().windowHeight - 50;
		}
	},
	onShareAppMessage() {
		return {
			title: '百灵心理'
			// ...其他配置
		};
	},
	onShow() {
		let userId = uni.getStorageSync('user_id');
		getInfos(userId).then((res) => {
			this.form = res.data;
		});
		getconfiguration({
			categoryName: '心理热线'
		}).then((res) => {
			this.data = res.data.configuration;
		});
	},
	methods: {
		goPhone() {
			// 判断手机是否支持拨打电话功能
			if (uni.canIUse('makePhoneCall')) {
				uni.makePhoneCall({
					phoneNumber: this.data, // 电话号码
					success: function () {},
					fail: function () {
						console.log('拨打电话失败');
					}
				});
			} else {
				console.log('你的设备不支持拨打电话功能');
			}
		},

		handleContact(e) {
			console.log('客服会话触发', e.detail); // 包含sessionFrom等参数
			// 可在此处记录用户行为或上报数据
		},
		handleAppointOrder() {
			this.$tab.navigateTo(`/subset/pages/consult/search/myConsult`);
		},
		handelMyEvaluate() {
			this.$tab.navigateTo(`/subset/pages/evaluate/search/myEvaluate`);
		},
		handelMyAtten() {
			this.$tab.navigateTo(`/subset/pages/consult/search/myAttent`);
		},
		backPay() {
			createRefund().then((res) => {});
		},
		goPay() {
			createOrder({
				description: '测试描述',
				outTradeNo: '989567234562111',
				totalFee: 1,
				wxOpenId: this.form.openId
			}).then((res) => {
				uni.requestPayment({
					timeStamp: res.data.timeStamp,
					nonceStr: res.data.nonceStr,
					package: res.data.packageVal,
					signType: res.data.signType,
					paySign: res.data.paySign,
					success: function (res) {
						console.log(res, 'success');
					},
					fail: function (res) {
						console.log(res, 'file');
					},
					complete: function (res) {
						console.log(res, 'complete');
					}
				});
			});
		},
		goInfo() {
			this.$tab.navigateTo(`/subset/pages/info/index`);
			// this.$tab.navigateTo(`/subset/pages/personInfo/personInfo`);
		},
		goSetting() {
			this.$tab.navigateTo(`/subset/pages/setting/index`);
		},
		goSugget() {
			this.$tab.navigateTo(`/subset/pages/suggest/index`);
		},
		onGetPhoneNumber(e) {
			if (e.detail.errMsg === 'getPhoneNumber:ok') {
				// 获取到加密数据和iv
				const { encryptedData, iv } = e.detail;
				console.log(e.detail);
				// 将加密数据和iv发送到你的服务器进行解密
				// uni.request({
				// 	url: 'https://your-server-domain.com/api/decrypt-phone', // 替换为你的服务器接口
				// 	method: 'POST',
				// 	data: {
				// 		encryptedData: encryptedData,
				// 		iv: iv
				// 	},
				// 	success: (response) => {
				// 		console.log('解密成功:', response.data);
				// 		// 在这里处理解密成功的逻辑，比如保存用户手机号到本地
				// 		uni.setStorageSync('userPhone', response.data.phoneNumber);
				// 	},
				// 	fail: (error) => {
				// 		console.error('解密失败:', error);
				// 	}
				// });
			} else {
				console.error('用户拒绝授权获取手机号');
			}
		},
		handleToInfo() {
			// this.$tab.navigateTo('/pages/mine/info/index')
		},
		handleToEditInfo() {
			// this.$tab.navigateTo('/pages/mine/info/edit')
		},
		handleToSetting() {
			// this.$tab.navigateTo('/pages/mine/setting/index')
		},
		handleToLogin() {
			// this.$tab.reLaunch('/pages/login')
			uni.login({
				success: (res) => {
					// console.log(res);
					this.$store
						.dispatch('Login', {
							code: res.code,
							publicOpenId: '',
							shareUserId: 0,
							userInfo: {
								age: '',
								avatarUrl: '',
								education: '',
								enterpriseDeptName: '',
								enterpriseName: '',
								factoryName: '',
								language: '',
								maritalStatus: '',
								medicalHistoryDescribe: '',
								medicalHistoryStatus: '',
								nickName: '',
								occupation: '',
								phone: '',
								sex: '',
								userId: 0
							}
						})
						.then(() => {
							this.$modal.closeLoading();
							this.loginSuccess();
						})
						.catch(() => {
							if (this.captchaEnabled) {
								this.getCode();
							}
						});
				}
			});
		},
		// 登录成功后，处理函数
		loginSuccess(result) {
			// 设置用户信息
			this.$store.dispatch('GetInfo').then((res) => {
				this.$tab.reLaunch('/pages/index');
			});
		},
		handleToAvatar() {
			// this.$tab.navigateTo('/pages/mine/avatar/index')
		},
		handleHelp() {
			// this.$tab.navigateTo('/pages/mine/help/index')
		},
		handleAbout() {
			// this.$tab.navigateTo('/pages/mine/about/index')
		},
		handleJiaoLiuQun() {
			// this.$modal.showToast('QQ群：①133713780(满)、②146013835(满)、③189091635')
		},
		handleBuilding() {
			// this.$modal.showToast('模块建设中~')
		}
	}
};
</script>

<style lang="scss" scoped>
.mine-container {
	width: 100%;
	height: 100%;
	background-color: #f5f4f8;
	overflow: hidden;
	.scrollWrap {
		width: 100%;
		height: 100%;
	}
	.header-section {
		width: 100%;
		height: 644rpx;
		position: relative;
		.bg {
			width: 100%;
			height: 100%;
			position: absolute;
			left: 0;
			top: 0;
		}
		.bg-wrap {
			width: 100%;
			height: 100%;
			position: absolute;
			left: 0;
			top: 0;
			.head-img {
				width: 100%;
				padding: 72rpx 0 60rpx 0;
				> view:nth-child(1) {
					width: 172rpx;
					height: 172rpx;
					position: relative;
					margin: auto;
					box-shadow: 0rpx 0rpx 12rpx rgba(0, 0, 0, 0.16);
					border-radius: 50%;
					border: 2rpx solid #ffffff;
					> image:nth-child(1) {
						width: 100%;
						height: 100%;
						border-radius: 50%;
					}
					> view {
						width: 40rpx;
						height: 40rpx;
						background-color: #ffffff;
						position: absolute;
						right: 12rpx;
						bottom: 0;
						border-radius: 50%;
						display: flex;
						justify-content: center;
						align-items: center;
						> image {
							width: 30rpx;
							height: 30rpx;
						}
					}
				}
				> view:last-child {
					width: 100%;
					margin-top: 32rpx;
					text-align: center;
					font-weight: 400;
					font-size: 32rpx;
					color: #333333;
				}
			}
			.operate-list {
				width: 100%;
				padding: 0 30rpx 0 32rpx;
				box-sizing: border-box;
				display: flex;
				flex-direction: row;
				flex-wrap: wrap;
				justify-content: space-between;
				> view {
					width: 328rpx;
					height: 112rpx;
					background: #ffffff;
					box-shadow: 0rpx 0rpx 12rpx rgba(0, 0, 0, 0.1);
					border-radius: 20rpx;
					padding: 0 78rpx 0 38rpx;
					box-sizing: border-box;
					display: flex;
					justify-content: space-between;
					align-items: center;
					> image {
						width: 78rpx;
						height: 78rpx;
					}
					> text {
						font-weight: 400;
						font-size: 28rpx;
						color: #666666;
					}
				}
				> view:nth-child(1),
				> view:nth-child(2) {
					margin-bottom: 32rpx;
				}
				.contact {
					> button {
						padding: 0;
						width: 100%;
						height: 100%;
						background-color: #fff;
						border: none;
						display: flex;
						justify-content: space-between;
						align-items: center;
					}
					button:after {
						border: none;
					}
					image {
						width: 78rpx;
						height: 78rpx;
					}
					text {
						font-weight: 400;
						font-size: 28rpx;
						color: #666666;
					}
				}
			}
		}
	}

	.content-section {
		width: 100%;
		padding: 0 30rpx 0 32rpx;
		box-sizing: border-box;
		margin-top: 26rpx;
		&-list {
			background: #ffffff;
			box-shadow: 0rpx 0rpx 12rpx rgba(0, 0, 0, 0.1);
			border-radius: 20rpx;
			padding: 0 12rpx 0 20rpx;
			box-sizing: border-box;
			> view {
				width: 100%;
				padding: 42rpx 0;
				display: flex;
				align-items: center;
				image {
					width: 32rpx;
					height: 32rpx;
				}
				text {
					margin-left: 10rpx;
					font-weight: 400;
					font-size: 26rpx;
					color: #666666;
				}
			}
			> view:nth-child(2) {
				border-top: 2rpx solid #eeeeee;
				border-bottom: 2rpx solid #eeeeee;
			}
		}
	}
}
</style>
